package com.ybkj.daijia.server.controller;

import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.common.MemberOrderVo;
import com.ybkj.daijia.common.PageVo;
import com.ybkj.daijia.common.PointVo;
import com.ybkj.daijia.common.Result;
import com.ybkj.daijia.page.Page;
import com.ybkj.daijia.page.Pageable;
import com.ybkj.daijia.page.domain.Sort;
import com.ybkj.daijia.server.freight.Order;
import com.ybkj.daijia.server.freight.Truck;
import com.ybkj.daijia.server.freight.TruckType;
import com.ybkj.daijia.server.freight.TruckTypeCompany;
import com.ybkj.daijia.server.mapper.DriverMapper;
import com.ybkj.daijia.server.model.Area;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.service.AreaService;
import com.ybkj.daijia.server.service.CompanyService;
import com.ybkj.daijia.server.service.CouponService;
import com.ybkj.daijia.server.service.DriverService;
import com.ybkj.daijia.server.service.ErrandService;
import com.ybkj.daijia.server.service.FreightService;
import com.ybkj.daijia.server.service.MemberService;
import com.ybkj.daijia.server.service.OrderLocationManyService;
import com.ybkj.daijia.server.service.OrderService;
import com.ybkj.daijia.server.service.WeixinManagerService;
import com.ybkj.daijia.server.service.WeixinManagerXOrderService;
import com.ybkj.daijia.server.service.ZhuancheService;
import com.ybkj.daijia.server.service.ZhuanxianService;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(value = "freight")
public class FreightController {

    @Autowired
    private FreightService freightService;
    @Autowired
    private ZhuancheService zhuancheService;
    @Autowired
    private ZhuanxianService zhuanxianService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private CouponService couponService;
    @Autowired
    private AreaService areaService;
    @Autowired
    private DriverService driverService;
    @Autowired
    private ApplicationEventMulticaster applicationEventMulticaster;
    @Autowired
    private SettingUtils settingUtils;
    @Autowired
    private WeixinManagerService weixinManagerService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private ErrandService errandService;
    @Autowired
    private DriverMapper driverMapper;
    @Autowired
    private WeixinManagerXOrderService weixinManagerXOrderService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderLocationManyService orderLocationManyService;

    /**
     * 跳转到添加订单页面
     */
    @RequestMapping(value = "add", method = RequestMethod.GET)
    public ModelAndView add(HttpSession session) {
        return new ModelAndView();

    }

    //追加
    @RequestMapping(value = "addmore/{id}", method = RequestMethod.GET)
    public ModelAndView addmore(HttpSession session, @PathVariable("id") Long id) {

//        Subject subject = SecurityUtils.getSubject();
//        if (subject.isPermitted("freight")) {
//            ModelAndView mv = new ModelAndView();
//
//            Order order = freightService.findOne(id);
//            Company company = companyService.findOne(order.getCompanyId());
//            List<TruckType> list = freightService.queryTruckTypes(order.getCompanyId());
//            mv.addObject("companyId", order.getCompanyId());
//            mv.addObject("companys", companyService.findAll());
//            mv.addObject("weixinManagers", weixinManagerService.findByCompany(company.getId()));
//            mv.addObject("lng", (order.getWaypoints() != null && order.getWaypoints().size() > 0 ? order.getWaypoints().get(0).getLng() : ""));
//            mv.addObject("lat", (order.getWaypoints() != null && order.getWaypoints().size() > 0 ? order.getWaypoints().get(0).getLat() : ""));
//            mv.addObject("truckTypes", list);
//            if (order.getStartTime().before(new Date())) {
//                order.setStartTime(new Date());
//            }
//            mv.addObject("freightOrder", order);
//            mv.addObject("waypoints", order.getWaypoints());
//            WeixinManagerXOrder weixinManagerXOrder = weixinManagerXOrderService.findByOrderId(id);
//            if (null != weixinManagerXOrder) {
//                mv.addObject("weixinManagerId", weixinManagerXOrder.getManagerId());
//            }
//
//            mv.addObject(CSRFTokenManager.CSRF_PARAM_NAME, CSRFTokenManager.getTokenForSession(session));
//            mv.addObject("initDate", new Date(System.currentTimeMillis() + 7200000));
//            mv.addObject("default", "freight");
//            mv.setViewName("order/addmore");
//
//            return mv;
//        } else {
//            throw new NoPermissionException();
//        }
        return new ModelAndView();
    }

    /**
     * 根据距离和时间按照公司的收费标准预估订单价格
     *
     * @param truckTypeId
     * @param time
     * @param mileage
     * @return
     */
    @RequestMapping(value = "getPrice", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> getPrice(
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam("time") String[] time,
        @RequestParam("mileage") String[] mileage) {
        Map<String, Object> result = new HashMap<String, Object>();
        return result;
    }

    /**
     * 后台直接创建货运订单
     *
     * @param passengerId
     * @param passengerName
     * @param passengerPhone
     * @param companyId
     * @param companyName
     * @param truckTypeId
     * @param truckTypeName
     * @param startTime
     * @param memo
     * @param flitting
     * @param receipt
     * @param receivedPay
     * @param payMount
     * @param startPrice
     * @param mileage
     * @param runTime
     * @param mileagePrice
     * @param runTimePrice
     * @param couponMoney
     * @param couponId
     * @param employId
     * @param budgetPay
     * @param waypoint
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "create", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> create(
        @RequestParam(value = "passengerId", required = false) Long passengerId,
        @RequestParam("passengerName") String passengerName,
        @RequestParam("passengerPhone") String passengerPhone,
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam(required = false, value = "companyName") String companyName,
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam("truckTypeName") String truckTypeName,
        @RequestParam("startTime") String startTime,
        @RequestParam(value = "memo", required = false) String memo,
        @RequestParam(value = "flitting", required = false) Boolean flitting,
        @RequestParam(value = "receipt", required = false) Boolean receipt,
        @RequestParam(value = "receivedPay", required = false) Boolean receivedPay,
        @RequestParam(value = "payMount", required = false) Double payMount,
        @RequestParam("preStartPrice") Double startPrice,
        @RequestParam("preMileage") Double mileage,
        @RequestParam("preRunTime") Integer runTime,
        @RequestParam(value = "preMileagePrice", required = false) Double mileagePrice,
        @RequestParam("preRunTimePrice") Double runTimePrice,
        @RequestParam(value = "couponMoney", required = false) Double couponMoney,
        @RequestParam(value = "couponId", required = false) Long couponId,
        @RequestParam(value = "employId", required = false) Long employId,
        @RequestParam("budgetPay") Double budgetPay,
        @RequestParam(value = "waypoint", required = false) String waypoint,
        @RequestParam(value = "fixPrice", required = false) Boolean fixedPrice,
        @RequestParam(value = "fixPriceMoney", required = false) Double fixPriceMoney)
        throws ParseException {
//
        Map<String, Object> result = new HashMap<String, Object>();
        return result;
    }

    /**
     * 跳转到货车类型页面
     *
     * @return
     */
    @RequestMapping(value = "truckTypes", method = RequestMethod.GET)
    public ModelAndView truckTypes() {
//	  try {
//	    Subject subject = SecurityUtils.getSubject();
//	    Principal principal = (Principal) subject.getPrincipal();
        ModelAndView mv = new ModelAndView();
//	    if (subject.isPermitted("freightTruck")) {
//	      List<Company> list = new ArrayList<Company>();
//	      if(principal.isCompanyType()){
//	        list=companyService.findAll();
//	      }else{
//	        list.add(companyService.findOne(principal.getCompanyId()));
//	      }
//	      mv.addObject("companys",list);
//	      mv.addObject("arealist",areaService.listAll());
//	      mv.setViewName("freight/trucktype");
//	      return mv;
//	    }else{
//	      throw new NoPermissionException();
//	    }
//    } catch (Exception e) {
//      e.printStackTrace();
//      return null;
//    }
        return mv;
    }

    /**
     * 查询货车类型
     *
     * @param companyName
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "truckTypeData", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> truckTypeData(
        @RequestParam(required = false, value = "companyName") String companyName)
        throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 查询单个货车类型
     *
     * @param truckTypeId
     * @return
     */
    @RequestMapping(value = "findByTruckTypeId", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findByTruckTypeId(
        @RequestParam("truckTypeId") Long truckTypeId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 修改货车类型
     *
     * @param truckTypeId
     * @param typeName
     * @param len
     * @param width
     * @param height
     * @param carryingCapacity
     * @param sequence
     * @param cangointotown
     * @param areaId
     * @return
     */
    @RequestMapping(value = "updateTruckType", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> updateTruckType(
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam(value = "typeName", required = false) String typeName,
        @RequestParam(value = "len", required = false) Double len,
        @RequestParam(value = "width", required = false) Double width,
        @RequestParam(value = "height", required = false) Double height,
        @RequestParam(value = "carryingCapacity", required = false) Double carryingCapacity,
        @RequestParam(value = "sequence", required = false) Integer sequence,
        @RequestParam(value = "cangointotown", required = false) Boolean cangointotown,
        @RequestParam(value = "areaId", required = false) Long areaId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 删除货车类型
     *
     * @param truckTypeId
     * @return
     */
    @RequestMapping(value = "deleteTruckType", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> deleteTruckType(
        @RequestParam("truckTypeId") Long truckTypeId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 创建货车类型
     *
     * @param companyId
     * @param companyName
     * @param typeName
     * @param len
     * @param width
     * @param height
     * @param carryingCapacity
     * @param sequence
     * @param cangointotown
     * @param areaId
     * @return
     */
    @RequestMapping(value = "createTruckType", method = RequestMethod.POST)
    @ResponseBody
    public Result<TruckType> createTruckType(
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam(required = false, value = "companyName") String companyName,
        @RequestParam("typeName") String typeName,
        @RequestParam("len") Double len,
        @RequestParam("width") Double width,
        @RequestParam("height") Double height,
        @RequestParam("carryingCapacity") Double carryingCapacity,
        @RequestParam("sequence") Integer sequence,
        @RequestParam("cangointotown") Boolean cangointotown,
        @RequestParam("areaId") Long areaId) {
        Result<TruckType> result = null;
//			return result;
//		}else{
//			throw new NoPermissionException();
//		}
        return result;
    }

    /**
     * 根据公司Id查询货车类型
     *
     * @param companyId
     * @return
     */
    @RequestMapping(value = "findByTruckTypeCompanyId", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> findByTruckTypeCompanyId(
        @RequestParam("companyId") Long companyId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 跳转订单页面
     *
     * @return
     */
    @RequestMapping("freightList")
    public ModelAndView freightList() {
        ModelAndView mv = new ModelAndView();
        return mv;
    }

    /**
     * 多条件查询订单数据
     *
     * @param orderNumber
     * @param clientPhone
     * @param driverPhone
     * @param companyName
     * @param startTime
     * @param endTime
     * @param orderType
     * @param status
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "orderlistData", method = RequestMethod.GET)
    public @ResponseBody
    Page<Map<String, Object>> orderListData(
        @RequestParam(required = false, value = "orderNumber") String orderNumber,
        @RequestParam(required = false, value = "clientPhone") String clientPhone,
        @RequestParam(required = false, value = "driverPhone") String driverPhone,
        @RequestParam(required = false, value = "companyName") String companyName,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        @RequestParam(required = false, value = "endFinishTime") String endFinishTime,
        @RequestParam(required = false, value = "startFinishTime") String startFinishTime,
        @RequestParam(required = false, value = "orderType") String[] orderType,
        @RequestParam(required = false, value = "status") Integer[] status,
        @RequestParam(required = false, value = "treatment") Boolean treatment,
        @RequestParam(required = false, value = "page") Integer page,
        @RequestParam(required = false, value = "rows") Integer rows
    ) throws ParseException {
        Page<Map<String, Object>> result = null;
        return result;
    }

    @RequestMapping(value = "exportOrder", method = RequestMethod.GET)
    public void exportOrder(
        @RequestParam(required = false, value = "orderNumber") String orderNumber,
        @RequestParam(required = false, value = "clientPhone") String clientPhone,
        @RequestParam(required = false, value = "driverPhone") String driverPhone,
        @RequestParam(required = false, value = "companyName") String companyName,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        @RequestParam(required = false, value = "endFinishTime") String endFinishTime,
        @RequestParam(required = false, value = "startFinishTime") String startFinishTime,
        @RequestParam(required = false, value = "treatment") Boolean treatment,
        @RequestParam(required = false, value = "orderType") String[] orderType,
        @RequestParam(required = false, value = "status") Integer[] status,
        HttpServletRequest req, HttpServletResponse response
    ) throws IOException, ParseException {
    }


    /**
     * 查询订单
     *
     * @param companyId
     * @param orderNo
     * @param employName
     * @param employPhone
     * @param passengerName
     * @param passengerPhone
     * @param truckType
     * @param status
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "orders", method = RequestMethod.GET)
    public ModelAndView list(
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam(required = false, value = "orderNo") String orderNo,
        @RequestParam(required = false, value = "employName") String employName,
        @RequestParam(required = false, value = "employPhone") String employPhone,
        @RequestParam(required = false, value = "passengerName") String passengerName,
        @RequestParam(required = false, value = "passengerPhone") String passengerPhone,
        @RequestParam(required = false, value = "truckType") String truckType,
        @RequestParam(required = false, value = "status") Integer status) throws ParseException {
//        Subject subject = SecurityUtils.getSubject();
//        Principal principal = (Principal) subject.getPrincipal();
//        if (subject.isPermitted("freight")) {
//            Page<Order> page = freightService.queryFreightOrder(companyId, orderNo, employName, employPhone, passengerName, passengerPhone, truckType, status);
        ModelAndView mv = new ModelAndView();
//            mv.addObject("page", page);
//            mv.addObject("companys", companyService.findAll());
//            mv.addObject("companyId", companyId);
//            mv.addObject("orderNo", orderNo);
//            mv.addObject("employName", employName);
//            mv.addObject("employPhone", employPhone);
//            mv.addObject("passengerName", passengerName);
//            mv.addObject("passengerPhone", passengerPhone);
//            mv.addObject("truckType", truckType);
//            mv.addObject("truckTypes", freightService.queryTruckTypes(companyId));
//            mv.addObject("status", status);
//            Company company = companyService.findOne(principal.getCompanyId());
//            mv.addObject("lng", company.getLongitude());
//            mv.addObject("lat", company.getLatitude());
//            mv.setViewName("freight/order");
//            return mv;
//        } else {
//            throw new NoPermissionException();
//        }
        return mv;
    }

    /**
     * 查询单个订单
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "findByOrderId", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> findByOrderId(
        @RequestParam("orderId") Long orderId) {
//        Subject subject = SecurityUtils.getSubject();
//        if (subject.isPermitted("freight")) {
//            Order order = freightService.findOne(orderId);
        Map<String, Object> map = new HashMap<String, Object>();
//            map.put("order", order);
//            return map;
//        } else {
//            throw new NoPermissionException();
//        }
        return map;

    }

    //取消订单
    @RequestMapping(value = "cancel", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> cancel(
        @RequestParam("id") Long id,
        @RequestParam("cause") String cause) {
//        Subject subject = SecurityUtils.getSubject();
//        if (subject.isPermitted("freight")) {
        Map<String, Object> map = new HashMap<String, Object>();
//            Order order = freightService.findOne(id);
//            Driver driver = null;
//            if (null != order.getEmployId()) {
//                driver = driverService.findOne(order.getEmployId());
//            }
//            Result<Order> result = freightService.cancelOrder(order, driver, cause);
//            if (result.isSuccess()) {
//                FreightOrderCancelEvent cancelEvent = new FreightOrderCancelEvent(order, driver, "adminCancel");
//                applicationEventMulticaster.multicastEvent(cancelEvent);
//                map.put("success", true);
//                map.put("message", "销单成功");
//            } else {
//                map.put("success", false);
//                map.put("message", result.getMessage());
//            }
//            return map;
//        } else {
//            throw new NoPermissionException();
//        }
        return map;
    }


    /**
     * 收回订单
     *
     * @param id
     * @param cause
     * @return
     */
    @RequestMapping(value = "callback", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> callback(Long id, String cause) {

        Map<String, Object> map = new HashMap<String, Object>();

        return map;
    }

    //备注
    @RequestMapping(value = "remark", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> remark(Long id,
        @RequestParam(required = false, value = "memo") String memo) {
        Map<String, Object> result = new HashMap<String, Object>();
        return result;
    }

    /**
     * 订单详情
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "orderDetails/{orderId}", method = RequestMethod.GET)
    public ModelAndView orderDetails(
        @PathVariable Long orderId) {
//        Subject subject = SecurityUtils.getSubject();
        ModelAndView mv = new ModelAndView();
//        }
        return mv;
    }

    /**
     * 订单详情
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "orderDetailsData", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> orderDetailsData(
        @RequestParam("orderId") Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 查询催单记录
     *
     * @return
     */
    @RequestMapping(value = "getCuidanOrders", method = RequestMethod.GET)
    public @ResponseBody
    List<Order> getCuidanOrders() {
        List<Order> cuidanOrders = new ArrayList<Order>();
//        return cuidanOrders;
        return cuidanOrders;
    }

    /**
     * 关闭催单提示框
     */
    @RequestMapping(value = "closeCuidan", method = RequestMethod.POST)
    public @ResponseBody
    void closeCuidan(Long orderId) {
    }

    /**
     * 派单
     *
     * @param driverId
     * @param orderId
     * @return
     */
    @RequestMapping(value = "paidan", method = RequestMethod.POST)
    public synchronized @ResponseBody
    Map<String, Object> paidan(Long driverId, Long orderId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    /**
     * 判断司机状态
     *
     * @param employId
     * @return
     */
    public Map<String, Object> getDriverBusy(Long employId) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    //条件查询货车
    @RequestMapping(value = "truckData", method = RequestMethod.GET)
    @ResponseBody
    public Page<Truck> truckData(
        @RequestParam(required = false, value = "company") String companyNames,
        @RequestParam(required = false, value = "truckTypeName") String truckTypes,
        @RequestParam(required = false, value = "carNumber") String carNumber,
        @RequestParam(required = false, value = "employName") String driverName,
        @RequestParam(required = false, value = "status") Integer[] status) {
//        Subject subject = SecurityUtils.getSubject();
//        Principal principal = (Principal) subject.getPrincipal();
//        String allstatus = "";
//        if (status != null) {
//            for (int i = 0; i < status.length; i++) {
//                allstatus += status[i];
//                if (i != status.length - 1) {
//                    allstatus += ",";
//                }
//            }
//        }
        Page<Truck> page = null;
//        if (principal.isCompanyType()) {
//            page = freightService.queryByParamsCars(companyNames, truckTypes, carNumber, driverName, allstatus);
//        } else {
//            page = freightService.queryByParamsCars(principal.getCompanyAbbreviation(), truckTypes, carNumber, driverName, allstatus);
//        }
        return page;
    }

    //获取附近服务人员
    @RequestMapping(value = "getEmployees", method = RequestMethod.GET)
    public @ResponseBody
    List<Map<String, Object>> getEmployees(
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam("startLat") Double startLat,
        @RequestParam("startLng") Double startLng) throws ParseException {
//        Subject subject = SecurityUtils.getSubject();
//        if (subject.isPermitted("freight")) {
        List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
        return listMap;
    }

    //查询车辆列表
    @RequestMapping(value = "trucks", method = RequestMethod.GET)
    public ModelAndView cars() throws ParseException {
        ModelAndView mv = new ModelAndView();
        return mv;

    }

    //根据昵称,工号,电话模糊查询司机
    @RequestMapping(value = "getDriver", method = RequestMethod.GET)
    public @ResponseBody
    List<Map<String, Object>> getDriver(String param) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        return list;

    }

    //根据id查询司机
    @RequestMapping(value = "getEmploy", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> getEmploy(Long employId) {
        Driver driver = driverService.findOne(employId);
        Map<String, Object> map = null;
        if (driver != null) {
            map = new HashMap<String, Object>();
            map.put("username", driver.getRealname());//工号
            map.put("phone", driver.getPhone());//电话
            map.put("lng", driver.getLastLongitude() == null ? driver.getLongitude()
                : driver.getLastLongitude());
            map.put("lat",
                driver.getLastLatitude() == null ? driver.getLatitude() : driver.getLastLatitude());
        }
        return map;

    }

    //保存车辆
    @RequestMapping(value = "createTruck", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> createCar(
        @RequestParam(value = "companyId", required = false) Long companyId,
        @RequestParam(value = "companyName", required = false) String companyName,
        @RequestParam("name") String name,
        @RequestParam("carNumber") String carNumber,
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam(required = false, value = "truckTypeName") String truckTypeName,
        @RequestParam(value = "employId", required = false) Long employId,
        @RequestParam(value = "employName", required = false) String employName)
        throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
//        }
        return map;
    }

    //查询单个车辆
    @RequestMapping(value = "queryTruck", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> queryTruck(
        @RequestParam("id") Long id) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    //修改车辆
    @RequestMapping(value = "updateTruck", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> updateTruck(
        @RequestParam("id") Long id,
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam(required = false, value = "companyName") String companyName,
        @RequestParam(required = false, value = "name") String name,
        @RequestParam(required = false, value = "carNumber") String carNumber,
        @RequestParam(required = false, value = "truckTypeId") Long truckTypeId,
        @RequestParam(required = false, value = "truckTypeName") String truckTypeName,
        @RequestParam(required = false, value = "status") Integer status,
        @RequestParam(required = false, value = "employId") Long employId,
        @RequestParam(required = false, value = "employName") String employName)
        throws ParseException {
//        if (subject.isPermitted("freightTruck")) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    //删除车辆

    /**
     * @param id
     * @return
     * @throws ParseException
     */
    @RequestMapping(value = "delete", method = RequestMethod.GET)
    public @ResponseBody
    Map<String, Object> delete(
        @RequestParam("id") Long id) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }


    @RequestMapping(value = "freightHeatMapData", method = RequestMethod.POST)
    public @ResponseBody
    List<PointVo> freightHeatMapData(
        @RequestParam(required = false, value = "year") Integer year,
        @RequestParam(required = false, value = "month") Integer month
    ) {
        List<PointVo> processed = new LinkedList<PointVo>();
//
        return processed;

    }

    @RequestMapping("freightMemberOrderData")
    public @ResponseBody
    PageVo<MemberOrderVo> freightMemberOrderData(
        @RequestParam(required = false, value = "type") Integer type,
        @RequestParam(required = false, value = "gradeId") Long gradeId,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        @RequestParam(required = false, value = "companyId") Long companyId
    ) {
//
        PageVo<MemberOrderVo> result = null;
        return result;

    }

    @RequestMapping(value = "pointDetails", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> pointDetails(Long id) {

//
        Map<String, Object> map = new HashMap<String, Object>();
//
        return map;

    }

    @RequestMapping("exportFreightMemberOrder")
    public void exportMemberOrder(
        @RequestParam(required = false, value = "companyId") Long companyId,
        @RequestParam(required = false, value = "startTime") String startTime,
        @RequestParam(required = false, value = "endTime") String endTime,
        @RequestParam(required = false, value = "type") Integer type,
        @RequestParam(required = false, value = "gradeId") Long gradeId,
        HttpServletRequest req, HttpServletResponse response
    ) throws IOException {
//        Subject subject = SecurityUtils.getSubject();
//        Principal principal = (Principal) subject.getPrincipal();
//        if (subject.isPermitted("statistics")) {
//            Date start = null;
//            Date end = null;
//            if (!StringUtils.isEmpty(startTime)) {
//
//                try {
//                    start = DateUtils.parseDate(startTime, "yyyy-MM-dd HH:mm");
//                } catch (ParseException e) {
//                    e.printStackTrace();
//                }
//
//            }
//
//            if (!StringUtils.isBlank(endTime)) {
//
//                try {
//                    end = DateUtils.parseDate(endTime, "yyyy-MM-dd HH:mm");
//                } catch (ParseException e) {
//                    e.printStackTrace();
//                }
//
//            }
//
//            PageVo<MemberOrderVo> list = null;
//            if (principal.isCompanyType()) {
//                list = freightService.freightMemberOrder(start, end, companyId, gradeId, type);
//            } else {
//                list = freightService.freightMemberOrder(start, end, principal.getCompanyId(), gradeId, type);
//            }
//
//
//            String[] head = new String[4];
//            List<List<String>> rowlist = new ArrayList<List<String>>();
//
//            head[0] = ("客户");
//            head[1] = ("所属公司");
//            head[2] = ("订单完成数量（单）");
//            head[3] = ("订单完成金额（元）");
//            for (MemberOrderVo a : list.getContent()) {
//                List<String> celllist = new ArrayList<String>();
//
//                celllist.add(a.getName() + "-" + a.getPhone());
//                celllist.add(a.getCompanyName());
//                celllist.add(a.getFinishNums() + "");
//                celllist.add(a.getMoney().toString());
//
//
//                rowlist.add(celllist);
//
//            }
//
//            ExcelUtil.export(req, response, head, rowlist);
//        } else {
//            throw new NoPermissionException();
//        }

    }

    /**
     * 新的创建货车类型
     *
     * @param typeName
     * @param len
     * @param width
     * @param height
     * @param carryingCapacity
     * @param sequence
     * @param cangointotown
     * @return
     */
    @RequestMapping(value = "newCreateTruckType", method = RequestMethod.POST)
    @ResponseBody
    public Result<TruckType> newCreateTruckType(
        @RequestParam("typeName") String typeName,
        @RequestParam("len") Double len,
        @RequestParam("width") Double width,
        @RequestParam("height") Double height,
        @RequestParam("carryingCapacity") Double carryingCapacity,
        @RequestParam("sequence") Integer sequence,
        @RequestParam("cangointotown") Boolean cangointotown,
        @RequestParam("img") String img) {
        Result<TruckType> result = null;
        return result;
    }

    /**
     * 开通货车类型
     *
     * @return
     */
    @RequestMapping(value = "subscribeTruckType", method = RequestMethod.POST)
    @ResponseBody
    public Result<TruckType> subscribeTruckType(
        @RequestParam("companyId") Long companyId,
        @RequestParam("companyName") String companyName,
        @RequestParam("areaId") Long areaId,
        @RequestParam("truckTypeId") Long truckTypeId) {
        Result<TruckType> result = new Result<TruckType>();
        return result;
    }

    /**
     * 修改货车类型
     *
     * @param truckTypeId
     * @param typeName
     * @param len
     * @param width
     * @param height
     * @param carryingCapacity
     * @param sequence
     * @param cangointotown
     * @return
     */
    @RequestMapping(value = "newUpdateTruckType", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> newUpdateTruckType(
        @RequestParam("truckTypeId") Long truckTypeId,
        @RequestParam(value = "typeName", required = false) String typeName,
        @RequestParam(value = "len", required = false) Double len,
        @RequestParam(value = "width", required = false) Double width,
        @RequestParam(value = "height", required = false) Double height,
        @RequestParam(value = "carryingCapacity", required = false) Double carryingCapacity,
        @RequestParam(value = "sequence", required = false) Integer sequence,
        @RequestParam(value = "cangointotown", required = false) Boolean cangointotown,
        @RequestParam(value = "img", required = false) String img) {
        Map<String, Object> map = new HashMap<String, Object>();
        return map;
    }

    @RequestMapping(value = "queryTruckTypeCompany", method = RequestMethod.GET)
    public @ResponseBody
    Page<TruckTypeCompany> queryCarTypeCompany(
        @RequestParam(required = true, value = "truckTypeId") Long truckTypeId,
        @RequestParam(required = false, value = "companyName") String companyName)
        throws ParseException {
        Page<TruckTypeCompany> page = new Page<TruckTypeCompany>() {
            @Override
            public int getTotalPages() {
                return 0;
            }

            @Override
            public long getTotalElements() {
                return 0;
            }

            @Override
            public int getNumber() {
                return 0;
            }

            @Override
            public int getSize() {
                return 0;
            }

            @Override
            public int getNumberOfElements() {
                return 0;
            }

            @Override
            public List<TruckTypeCompany> getContent() {
                return null;
            }

            @Override
            public boolean hasContent() {
                return false;
            }

            @Override
            public Sort getSort() {
                return null;
            }

            @Override
            public boolean isFirst() {
                return false;
            }

            @Override
            public boolean isLast() {
                return false;
            }

            @Override
            public boolean hasNext() {
                return false;
            }

            @Override
            public boolean hasPrevious() {
                return false;
            }

            @Override
            public Pageable nextPageable() {
                return null;
            }

            @Override
            public Pageable previousPageable() {
                return null;
            }

            @Override
            public Iterator<TruckTypeCompany> iterator() {
                return null;
            }
        };
        return page;
    }


    @RequestMapping(value = "updateTruckTypeCompany", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> updateTruckTypeCompany(
        @RequestParam("id") Long id,
        @RequestParam("areaId") Long areaId) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();

        return map;
    }

    @RequestMapping(value = "deleteTruckTypeCompany", method = RequestMethod.POST)
    public @ResponseBody
    Map<String, Object> deleteTruckTypeCompany(
        @RequestParam("truckTypeCompanyId") Long truckTypeCompanyId) throws ParseException {
        Map<String, Object> map = new HashMap<String, Object>();

        return map;
    }


    @RequestMapping(value = "updateRealMoney", method = RequestMethod.POST)
    public synchronized @ResponseBody
    Result<Order> updateRealMoney(
        Long id, BigDecimal couponMoney, BigDecimal cashMoney, BigDecimal signMoney,
        BigDecimal balanceMoney,
        BigDecimal alipayMoney, BigDecimal weixinMoney, String content,
        BigDecimal driverMoney, Integer driverPlusMinus,
        BigDecimal memberMoney, Integer memberPlusMinus,
        @RequestParam(required = false, value = "wxMoney") BigDecimal wxMoney,
        @RequestParam(required = false, value = "wxPlusMinus") Integer wxPlusMinus) {
        Result<Order> vo = new Result<Order>();
//
        return vo;
    }

    private boolean isAreaIdExist(List<Area> areaList, long id, boolean flag) {
        return flag;
    }
}

